package com.lntu.meeting.service.impl;

import com.alibaba.fastjson.JSON;
import com.lntu.meeting.dao.UserDao;
import com.lntu.meeting.pojo.User;
import com.lntu.meeting.service.UserService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public String getUser(User user) {
        String flag = "500";
        String uname = user.getUname();
        String upwd = user.getUpwd();
        if (StringUtils.isBlank(uname) && StringUtils.isBlank(upwd)){
            Map<String,Object> resMap = new HashMap<>();
            resMap.put("flag", flag);
            String res = JSON.toJSONString(resMap);
            return res;
        }

        User user1 = userDao.getUser(uname, upwd);
        System.out.println(user1);
        if (user1!=null){
            flag = "200";
        }
        System.out.println(flag);
        Map<String,Object> resMap = new HashMap<>();
        resMap.put("flag", flag);
        resMap.put("data", user1);
        String res = JSON.toJSONString(resMap);
        return res;
    }
}
